package cc.yaomm.service.basic.mapper.user;

import cc.yaomm.common.basic.base.SuperMapper;
import cc.yaomm.common.biz.enums.LoginTypeEnum;
import cc.yaomm.common.biz.enums.UserTypeEnum;
import cc.yaomm.service.basic.entity.user.Users;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Set;

@Mapper
public interface UsersMapper extends SuperMapper<Users> {

    /**
     * 查询登录账号
     *
     * @param account
     * @param typeEnums
     * @return
     */
    default List<Users> findLoginAccount(final String account, LoginTypeEnum loginType, Set<UserTypeEnum> typeEnums) {
        LambdaQueryWrapper<Users> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(Users::getType, typeEnums);
        wrapper.eq(loginType == LoginTypeEnum.ACCOUNT, Users::getAccount, account);
        wrapper.eq(loginType == LoginTypeEnum.PHONE, Users::getPhone, account);
        wrapper.eq(loginType == LoginTypeEnum.WECHAT, Users::getWxOpenId, account);
        return selectList(wrapper);
    }
}
